import { ajaxCommonParams, jsonpCommonParams, jsonpOptions } from 'api/config'
import jsonp from 'common/js/jsonp'

export const getSingerList = () => {
  // https://c.y.qq.com/v8/fcg-bin/v8.fcg
  const url = 'https://c.y.qq.com/v8/fcg-bin/v8.fcg'

  const data = Object.assign(jsonpCommonParams, {
    channel: 'singer',
    page: 'list',
    key: 'all_all_all',
    pagesize: 100,
    pagenum: 1,
    hostUin: 0,
    needNewCode: 0,
    platform: 'yqq'
  })

  return jsonp(url, data, jsonpOptions)
}

/**
export const getSingerDetail = () => {
  const url = `v8/fcg-bin/fcg_v8_singer_track_cp.fcg`

  const data = Object.assign(ajaxCommonParams, {
    jsonpCallback: 'MusicJsonCallbacksinger_track',
    format: 'jsonp',
    inCharset: 'utf8',
    outCharset: 'utf-8',
    loginUin: 0,
    hostUin: 0,
    platform: 'yqq',
    needNewCode: 0,
    singermid: '002J4UUk29y8BY',
    order: 'listen',
    begin: 0,
    num: 30,
    songstatus: 1
  })

  eslint-disable
  axios({method:'get',baseURL:'/api',url, data}).then(res => {
    console.log(res);
  });
};
*/

/**
 * JSONP的方式获取歌曲数据
 */
export const getSingerDetailJSONP = (mid) => {
  const url = `https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg`

  const data = Object.assign(jsonpCommonParams, {
    // jsonpCallback: 'MusicJsonCallbacksinger_track',
    format: 'jsonp',
    inCharset: 'utf8',
    outCharset: 'utf-8',
    loginUin: 0,
    hostUin: 0,
    platform: 'yqq',
    needNewCode: 0,
    singermid: mid,
    order: 'listen',
    begin: 0,
    num: 100,
    songstatus: 1
  })

  return jsonp(url, data, jsonpOptions)
}

/**
 * 服务器代码获取歌曲列表数据
 * @param {*} mid
 */
export const getSingerDetailProxy = (mid) => {
  const url = `api/getSongList`

  const data = Object.assign(ajaxCommonParams, {
    loginUin: 0,
    hostUin: 0,
    platform: 'yqq',
    needNewCode: 0,
    singermid: mid,
    order: 'listen',
    begin: 0,
    num: 60,
    songstatus: 1
  })

  /* eslint-disable */
  return axios.get(url, {params:data}).then(response => {
    return Promise.resolve(response)
  })
}
